package exia.java.core.services;

import net.sf.hibernate.HibernateException;
/**
 * 
 * @author Jeannette Sebastien
 *
 */
public class RemoteServiceFactory {
	
	private static IServiceLivre serviceLivre = null;
	private static IServiceUtilisateur serviceUtilisateur = null;
	private static IServiceCommande serviceCommande = null;
	private static IServiceAuthentification serviceAuthentification = null;
	
	/**
	 * 
	 */
	public RemoteServiceFactory(){
		super();
	}
	
	/**
	 * 
	 * @return
	 */
	public static IServiceAuthentification getServiceAuthentification(){
		if(serviceAuthentification == null){
			serviceAuthentification = new HibernateServiceAuthentificationImpl();
		}
		return serviceAuthentification;
	}
	
	/**
	 * 
	 * @return
	 */
	public static IServiceLivre getServiceLivre(){
		if(serviceLivre == null){
			try {
				serviceLivre = new HibernateServiceLivreImpl(HibernateUtil.createSession());
			} catch (HibernateException ex) {
				ex.printStackTrace();
			} 
		}
		return serviceLivre;
	}
	
	/**
	 * 
	 * @return
	 */
	public static IServiceUtilisateur getServiceUtilisateur(){
		if(serviceUtilisateur == null){
			try {
				serviceUtilisateur = new HibernateServiceUtilisateurImpl(HibernateUtil.createSession());
			} catch (HibernateException ex) {
				ex.printStackTrace();
			}
		}
		return serviceUtilisateur;
	}
	
	/**
	 * 
	 * @return
	 */
	public static IServiceCommande getServiceCommande(){
		if(serviceCommande == null){
			try {
				serviceCommande = new HibernateServiceCommandeImpl(HibernateUtil.createSession());
			} catch (HibernateException ex) {
				ex.printStackTrace();
			}
		}
		return serviceCommande;
	}
}
